package com.example.demo.service.Impl;


import com.example.demo.dao.IUsers;
import com.example.demo.model.Users;
import com.example.demo.service.IUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Administrator 张喜英
 */

@Service
public class UsersServiceImpl implements IUsersService{

    @Autowired
    private IUsers usersMapper;
    @Override
    public int insertUsers(Users users){
        int userValue=0;
        System.out.println(users.getYhid());
       Users users1=new Users();
        users1.setYhid(users.getYhid());
        List<Users> getU=usersMapper.getAllUsers(users1);
        if(getU.size()>0){
            userValue=-1;

        }else{
            userValue=usersMapper.insertUsers(users);
        }

        return userValue;
    }

    @Override
    public List<Users> getAllUsers(Users users) {


        return usersMapper.getAllUsers(users);
    }

    @Override
    public int updateUsers(Users users) {
        int userValues=0;
        if(users.getYhid()!=0){



            userValues=usersMapper.updateUsers(users);
        }
        return userValues;
    }

    @Override
    public int deleteUsers(Users users) {
        int userValues=0;
        if(users.getYhid()!=0)
        {
            //主键是否与其他表有关联

           userValues=usersMapper.deleteUsers(users);
        }
        return userValues;
    }

    @Override
    public Users getUsers(Users users) {
        Users users1=new Users();
        if(users.getYhid()!=0){
            users1=usersMapper.getUsers(users);
        }
        return users1;
    }

}
